package com.saftalk.util;

import java.io.UnsupportedEncodingException;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;


public class Emailer {

	public Emailer() {
		
	}

	public static void send(String name, String email, String password) {
		Properties props = new Properties();
		Session session = Session.getDefaultInstance(props, null);

		String msgBody = "Hello, " + name + "!\nYou were added to the Saftalk system!\n" +
				"Your Username is: " + email +"\n" +
				"Your password is: " + password + "\n";

		try {
			Message msg = new MimeMessage(session);
			msg.setFrom(new InternetAddress("admin@saftalkapp.appspotmail.com",
					"Saftalk System"));
			msg.addRecipient(Message.RecipientType.TO, new InternetAddress(
					email, name));
			msg.setSubject("Your Saftalk Account");
			msg.setText(msgBody);
			Transport.send(msg);

		} catch (AddressException e) {
			e.printStackTrace();
			// ...
		} catch (MessagingException e) {
			e.printStackTrace();
			// ...
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			
		}
	}

}
